local db = require "src/bdc/DB"
-- 读取文件
-- "D:\_life\mygithub\studyday21\bdc01\txt\markdownrules.txt"
--[[
local file1=io.input("D:/_life/mygithub/studyday21/bdc01/txt/markdownrules.txt")  
local str=io.read("*a")
print(str)
--]]
--[[
从一行中解析单词
--]]
function parseLine(line,result)  
  lines = string.gmatch(line,"%a+");
  -- 如何打印 
    for v in lines do
      if v ~= nil  then
      table.insert(result,v);
      end
    end

end
  
--[[
从text中解析单词
--]]
function parseText(filepath)  
  result = {};
  local file1 = io.input(filepath);
  for line in file1:lines() do
    parseLine(line,result);
  end
  return result;
end

--[[
local result = {};
local count = 0;
local file1=io.input("D:/_life/mygithub/studyday21/bdc01/txt/markdownrules.txt")  
for line in io.lines() do
  count = count+1;
  parseWord(line,result);
  --print("--------------------------------------------")
  --io.write(string.format("%6d ",count),line,"\n");
end
--]]

--[[
实现去除重复单词
--]]
function markRepeat(result1,length)  
  -- 遍历列表，如果列表列表中已经存在则设置为nil
  -- 考虑边界的情况
  for j = 1, length-1 do
  --print("xx",j,"----------",result1[j])
  ---[[
    for i = j+1,length do
       --print("yy",i,"----------",result1[i])
      if result1[j] == nil then
        goto continue;
      end
      if result1[i] == nil then
        goto continue0;
      end
      if result1[j] == result1[i] then
        result1[i] = nil;
      end
      ::continue0::
    end
    
    ::continue::
    
    --]]
  end
end


--下一步建立main方法，开始写，避免这些直接写
--[[
函数入口
--]]
function main(filePath)
  local result1 = parseText(filePath);
  local length = #result1;
  markRepeat(result1,length)
  for i=1,length do
    print(result1[i])
  end
end

local filePath = "D:/_life/mygithub/studyday21/bdc01/txt/test.txt";
-- main(filePath);

db.exec("select * from test")